package com.app.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.bean.Movies;
import com.app.bean.News;
import com.app.bean.NewsExample;
import com.app.bean.NewsExample.Criteria;
import com.app.mapper.NewsMapper;
import com.app.util.StringUtilsEx;

@Service
public class NewsService {
	
	@Autowired
	NewsMapper mapper; 
	
	public int add(News news) {
		news.setPublishdate(StringUtilsEx.now());
		return mapper.insert(news);
	}

	public News getById(String id) {
		return mapper.selectByPrimaryKey(Integer.parseInt(id));
	}

	public void delete(String id) {
		mapper.deleteByPrimaryKey(Integer.parseInt(id));
	}

	public void update(News news) {
		mapper.updateByPrimaryKey(news);
	}

	public List<News> list(String newsname) {
		
		NewsExample example = new NewsExample();
		Criteria criteria = example.createCriteria();
		
		criteria.andTitleLike("%"+newsname+"%");
		
		List<News> list = mapper.selectByExample(example);
		
		return list;
	}
}
